package br.edu.ufcg.dsc.psoo.mymoney.model.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.mentawai.bean.BeanBase;

/**
 * Bean de usu�rio <br>
 * Anotado com configura��es do <b>Hibernate</b>
 * 
 * @author leonardo
 * @version 1.0
 */
@Entity
@Table(name = "users", schema = "psoo")
public class User extends BeanBase implements Serializable {

	@Transient
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Long id;

	@Column(name = "username", nullable = false, length = 20)
	private String username;

	@Column(name = "password", nullable = false, length = 20)
	private String password;

	@Transient
	private String confirmation;

	@Column(name = "email", nullable = false, length = 40)
	private String email;

	@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, targetEntity = Type.class)
	@Cascade(CascadeType.ALL)
	private Collection<Type> types;

	@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, targetEntity = Account.class)
	@Cascade(CascadeType.ALL)
	private Collection<Account> accounts;

	/**
	 * @return the accounts
	 */
	public Collection<Account> getAccounts() {
		return accounts;
	}

	/**
	 * @param accounts
	 *            the accounts to set
	 */
	public void setAccounts(Collection<Account> accounts) {
		this.accounts = accounts;
	}

	/**
	 * @return tipos criados pelo usu�rio
	 */
	public Collection<Type> getTypes() {
		return types;
	}

	/**
	 * @param types
	 */
	public void setTypes(Collection<Type> types) {
		this.types = types;
	}

	/**
	 * @return the serialVersionUID
	 */
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	/**
	 * 
	 */
	public User() {
	}

	/**
	 * Construtor padrao
	 * 
	 * @param username
	 *            nome do usu�rio
	 * @param password
	 *            password
	 * @param email
	 *            email
	 */
	public User(String username, String password, String email) {
		this.username = username;
		this.password = password;
		this.email = email;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return username;
	}

	/**
	 * @return Confirma��o de password
	 */
	public String getConfirmation() {
		return confirmation;
	}

	/**
	 * @param confirmation
	 */
	public void setConfirmation(String confirmation) {
		this.confirmation = confirmation;
	}

	/**
	 * @return id do usu�rio
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return login do usu�rio
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return password do usu�rio
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return email do usu�rio
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 */
	public void setEmail(String email) {
		this.email = email;
	}
}